###
 # @Description: 抓阄项目
 # @Version: 2.0
 # @Autor: gang
 # @Date: 2020-09-24 13:43:07
 # @LastEditors: gang
 # @LastEditTime: 2020-09-24 14:20:15
### 
#!/bin/bash
function random(){
    random=$((RANDOM%100))
    if [ `egrep -w "${random}" /tmp/name.log | wc -l` -ge 1 ]
        then
        continue
    fi
}

function name(){
    read -p "请输入你的名字的全拼:" name
    if [ "${name}" = "exit" ]
        then
        break
    fi
    #判断记录，是否存在
    if [ `egrep -w "$name" /tmp/name.log | wc -l` -ge 1 ]
        then
        echo "名字重复，请重新输入"
        continue
    fi
    echo -e "${random}\t\t$name" | tee -a /tmp/name.log
}

function main(){
    while true
    do
        random
        name
    done
    echo "抓阄结束，排序如下："
    sort -rn -k1 /tmp/name.log
}
main